/**
 * Copyright (C) 2011 Denatics Development
 *
 * Programmed by David Tiersch <dtiersch@denatics.com>
 *
 * This file is part of B0mberman.
 *
 * B0mberman is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * B0mberman is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with B0mberman. If not, see <http://www.gnu.org/licenses/>.
 */
package com.denatics.bomberman.engine;

import java.util.ArrayList;
import java.util.List;

import com.denatics.bomberman.entities.Blank;
import com.denatics.bomberman.entities.Entity;
import com.denatics.bomberman.sprites.Sprite;
import com.denatics.bomberman.tools.Debugger;

/**
 * This is a single Tile. On it can be different Entities such as a wall or a
 * player.
 *
 * @author David Tiersch <dtiersch@denatics.com>
 */
public final class Tile {

    /**
     * Which entity resides on this Tile.
     */
    private Entity block;

    /**
     * Which sprites belong to this Tile.
     */
    private List<Sprite> sprites;

    /**
     * Creates the Tile.
     */
    public Tile() {
        this.block = new Blank();
        this.sprites = new ArrayList<Sprite>();
    }

    /**
     * Creates the Tile.
     *
     * @param entity
     *            Entity which shall be applied to this tile
     */
    public Tile(final Entity entity) {
        this.block = entity;
        this.sprites = new ArrayList<Sprite>();
    }

    /**
     * Returns the Entitiy which is attached to this Tile.
     *
     * @return Entity
     */
    public Entity getEntity() {
        return this.block;
    }

    /**
     * Sets the Entity of this Tile.
     *
     * @param entity
     *            new Entity
     */
    public void setEntity(final Entity entity) {
        this.block = entity;
    }

    /**
     * Adds a sprite to this Tile.
     *
     * @param newSprite
     *            Sprite to be added
     */
    public void addSprite(final Sprite newSprite) {
        this.sprites.add(newSprite);
        Debugger.printDebug("Sprite added");
    }

    /**
     * Removes a sprite from this Tile.
     *
     * @param removeSprite
     *            Sprite to be removed
     */
    public void removeSprite(final Sprite removeSprite) {
        if (this.sprites.remove(removeSprite)) {
            removeSprite(removeSprite);
        }
        Debugger.printDebug("Sprite removed");
    }

    /**
     * Returns the Sprites which are attached to this Tile.
     *
     * @return Sprites
     */
    public List<Sprite> getSprites() {
        return this.sprites;
    }
}
